package com.origin.niuke.simulation;

import java.util.Arrays;

/**
 * @author yzh
 * @version 1.0
 * @date 2022/7/14 8:47
 * 大数相乘
 * 算法：模拟
 */
public class NC10 {
    public static void main(String[] args) {
        System.out.println(new NC10().solve("12", "1000"));
    }

    public String solve (String s, String t) {
        int m = s.length(), n = t.length();
        if (m == 0 || n == 0 || "0".equals(s) || "0".equals(t)) return "0";
        int[] nums = new int[m + n];
        for (int i = m - 1; i >= 0; i--) {
            int x = s.charAt(i) - '0';
            for (int j = n - 1; j >= 0; j--) {
                int y = t.charAt(j) - '0';
                nums[m + n - i - j - 2] += x * y;
            }
        }
        System.out.println(Arrays.toString(nums));
        for (int i = 0; i < m + n - 1; i++) {
            nums[i + 1] += nums[i] / 10;
            nums[i] %= 10;
        }
        System.out.println(Arrays.toString(nums));
        int idx = nums[m + n - 1] != 0 ? m + n - 1 : m + n - 2;
        StringBuilder ans = new StringBuilder();
        for (; idx >= 0; idx--) ans.append(nums[idx]);
        return ans.toString();
    }

}
